﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Inspect_Contracts";
}
@section styles{
    <style>
        td {
            width: 150px;
            text-align-last: left;

        }
        table{
            width:auto;
            table-layout:auto
        }
        /*span {
            background-color: gray;
            text-align: center;
            color: white;
            border: 1px solid black;
            width: 100px;
        }*/

        WY_tbody_zc td {
            border-bottom: 1px solid black;
        }

        fieldset div {
            margin-bottom: 5px;
            margin-left: 5px;
        }
    </style>
}
<fieldset class="boun">
    <legend></legend>
    <div class="row bian">
        <label class="col-sm-3 breadcrumb-item ">设计委托</label>
        <ul id="lisul" class="row col-sm-5">
        </ul>
    </div>
</fieldset>
<fieldset class="boun">
    <legend class="len">@Resource.String155</legend>
    <div class="row">
        <div class="col-2">创建日期从：</div>
        <div class="col-2"><input type="date" id="qssj" /></div>
        <div class="col-1">到:</div>
        <div class="col-2"><input type="date" id="jssj" /></div>
        <div class="col-4"></div>
    </div>
    <div class="row">
        <div class="col-2">申请单号</div>
        <div class="col-2"><input type="text" id="bian" /></div>
        <div class="col-1">@Resource.String375</div>
        <div class="col-2"><input type="text" id="BB_SQ_xmmc" /></div>
        <div class="col-1">@Resource.String376</div>
        <div class="col-2"><input type="text" id="BB_SQ_khmc" /></div>
    </div>
    <div class="row">
        <div class="col-2">关键词搜索</div>
        <div class="col-2"><input type="text" id="BB_SQ_gjz" /></div>
        <div class="col-2">项目状态</div>
        <div class="col-2" style="text-align:left">
            <select id="xmlx">
                <option value="0">请选择</option>
                <option value="WON Opportunities">WON Opportunities</option>
                <option value="OPEN Opportunities">Open Opportunities</option>
                <option value="LOST Opportunities">LOST Opportunities</option>
            </select>
        </div>
        <div class="col-2"></div>
        <div class="col-2 Hides">是否递交</div>
        <div class="col-2 Hides" style="text-align:left">
            <select id="SSFdj">
                <option value="2">未递交</option>
                <option value="1">已递交</option>
            </select>
        </div>
        <div class="col-2 btn-sm  btn-warning" id="BB_WT_cxssss" style="text-align:center">@Resource.String374</div>
    </div>
</fieldset>
<from>
    <div style="margin-top:12px;">
        <fieldset class="boun">
            <div id="WT_zcym" style="display:block">
                <table class="table table-sm gun">
                    <thead class="thead-light">
                        <tr>
                            <td>@Resource.String189</td>
                            <td style="width:20vh">@Resource.String180</td>
                            <td style="width:26vh">@Resource.String193</td>
                            <td>@Resource.String191</td>
                            <td>@Resource.String199</td>
                            <td>设计接单人</td>
                            <td>@Resource.String200</td>
                            <td>@Resource.String593</td>
                            <td>@Resource.String178</td>
                            <td>驳回理由</td>
                        </tr>
                    </thead>
                    <tbody id="WY_tbody_zc">
                    </tbody>
                </table>
            </div>
        </fieldset>
    </div>
    <div id="WT_dh_mb" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1">
        <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div id="WJ_ID" style="display:none"></div>
        <table>
            <tr>
                <td>@Resource.String201：</td>
                <td id="WT_dhr"></td>
            </tr>
            <tr>
                <td>@Resource.String202</td>
                <td><textarea id="WT_dhly"></textarea></td>
            </tr>
            <tr>
                <td class="WT_qxbh">退出</td>
            </tr>
        </table>
    </div>
</from>
<div id="kejks" style="display:none"></div>
<div>
    <div style="display: flex; justify-content: space-between;">
        <span>共 <span id="Hangs"></span> 行</span>
        @using (Html.BeginForm("Cliview", "Application", FormMethod.Post))
        {<nav aria-label="Page navigation example" class="row" style="margin-right:50px;">
                <ul class="pagination">
                </ul>
                共<span id="komdr"></span>页
            </nav>
        }
    </div>
</div>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        //点击切换查看已提交委托和暂存委托
        $(function () {
            $("#li2").css({ "color": "black", "background-color": "white" })
            DAyin(0)
            //搜索
            $(document).on("click", "#BB_WT_cxssss", function () {
                //打印暂存页
                DAyin(0)
            })
            function DAyin(a) {
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                var Namess = $("#Login_name").text()
                var SFDJ = $("#SSFdj").val()
                //暂存
                $.ajax({
                    url: '/Contracts/Inspect_Contracts',
                    type: 'GET',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "state": 1, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx, "Namess": Namess, "shunfl": a - 1, "JIN": SFDJ },
                    success: function (zc) {
                        hanghao(a)
                        newzc(zc);
                    },
                    error: function () {
                        console.log("失败");
                    }
                })
            }
            function hanghao(p) {
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                var Namess = $("#Login_name").text()
                var SFDJ = $("#SSFdj").val()
                //暂存
                $.ajax({
                    url: '/Contracts/Inspect_Contracts',
                    type: 'GET',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "state": 8, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx, "Namess": Namess, "JIN": SFDJ },
                    success: function (date) {
                        var HJ = date * 1
                        var HNH = HJ / 10 < 1 ? 1 : Math.ceil(HJ / 10)
                        $("#Hangs").text(HJ)
                        $("#komdr").text(HNH)
                        p = p == 0 ? 1 : p
                        fenye(p)
                    },
                    error: function () {
                        console.log("失败");
                    }
                })
            }
            function newzc(zc) {
                $('#WY_tbody_zc tr').remove();
                var num = $("#Login_N").text()
                var sf = $("#Login_sf").text()
                var bm = $("#Login_bm").text()
                var zj = $("#Login_zj").text()

                $.each(zc, function (i, item) {
                    //console.log($("#kejks").text())
                   @* var iteskm = item.D_zhuang == "1"?"@Resource.String1262":item.D_zhuang == "2" ? "@Resource.String1263" : item.D_zhuang == "3" ? "@Resource.String1264" : item.D_zhuang == "4" ? "@Resource.String1265" : item.D_zhuang == "5" ? "@Resource.String1266" : "@Resource.String1267";*@
                    var $zc =
                            $(`<tr>
                                   <td style="width:60px;display:none">${item.D_id}</td>
                                        <td>${item.D_Ton}</td>
                                        <td>${item.D_CN}</td>
                                        <td>${item.D_PN}</td>
                                        <td>${item.D_Applic}</td>
                                        <td>${item.D_reDate}</td>
                                        <td>${item.D_SR}</td>
                                        <td>${item.D_App}</td>
                                        <td>${item.D_JL}</td>
                                        <td><a href="#" id="WT_bjwt">@Resource.String204</a></td>
                                        <td><a href="#" id="BH_JL">驳回理由</a></td>
                                    </tr>
                                `);
                    $('#WY_tbody_zc').append($zc);
        /*
                    if (bm == "业务") {
                        if (sf == "销售助理" || sf == "客户经理") {
                            $('#WY_tbody_zc').append($zc);
                        }
                        else {
                            var num = $("#Login_N").text()
                            if (num == item.D_App) {
                                $('#WY_tbody_zc').append($zc);
                            }
                        }
                    }
                    else if (bm == "设计") {
                        if (zj == "2") {
                            //if (item.D_zhuang == "3") {
                            //    $('#WY_tbody_zc').append($zc);
                            //}
                            //else if (item.D_zhuang == "2") {
                                $('#WY_tbody_zc').append($zc);
                            //}
                        }
                        if (item.D_zhuang == "3" && zj == "1") {

                            var SFDJ = $("#SSFdj").val()
                            $.ajax({
                                url: '/Contracts/Inspect_Contracts',
                                type: 'GET',
                                data: { "D_ID": $("#Login_name").text(), "D_Ton": item.D_Ton, "state": 7, "JIN": SFDJ },
                                success: function (zced) {
                                    if (zced == "添加") {
                                        $('#WY_tbody_zc').append($zc);
                                    }
                                },
                                error: function () {
                                    console.log("失败");
                                }
                            })
                        }
                    }*/

                })
            }
            //打印提交页
            newtj()
            function newtj() {
                var sf = $("#Login_sf").text()
                if (sf == "设计员") {
                    $(".Hides").show()
                } else {
                    $(".Hides").hide()
                }
            }
            function find_liy(id) {
                $.ajax({
                    url: '/Contracts/Inspect_Contracts',
                    type: 'GET',
                    data: { "D_ID": id,"state": 2 },
                    success: function (zced) {
                        $.each(zced, function (i, obj) {
                            console.log(obj.D_dhly)
                            $("#WT_dhly").val(obj.D_dhly)
                            $("#WT_dhr").text(obj.D_dhr)
                        })
                    },
                    error: function () {
                        console.log("失败");
                    }
                })
            }

            function xx(e) {
                var id = e.parent().parent().children().eq(1).text()
                var index = e.text()
                var zhuang = ""
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var time = year + "/" + month + "/" + date
                var num = $("#Login_N").text()
                if (index == "@Resource.String207") {
                    zhuang = "5"
                }
                else {
                    zhuang="-99"
                }
                var BZJG = [];
                BZJG.push({
                    D_Ton: id,
                    D_zhuang: zhuang,
                    D_CD: time,
                    D_TCA: num
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Contracts/Modify_des_zhuang2",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        if (text == "Y") {
                            window.location.href = "/Detailed/Boms?names=" + id;
                        } else if (text == "S") {
                            alert("设计结束")
                        }
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }

            //单机完成设计委托
            $(document).on("click", "#WT_SJWC", function (e) {
                xx($(e.target))
            })

            //点击关闭驳回面板
            $(document).on("click", ".WT_qxbh", function (e) {
                $("#WT_dh_mb").css({ "display": "none" })
                $("#WT_dhly").val("")
                $("#WT_dhr").text("")
                $("#WJ_ID").text("")
            })
            //点击查看设计主管的打回理由
            $(document).on("click", "#WT_CKLY", function (e) {
                id = $(e.target).parent().parent().parent().children().first().text()
                find_liy(id)
                $("#WT_dh_mb").css({ "display": "block" })
            })
            //转跳到添加日志页
            $(document).on("click", "#WT_tjrz", function (e) {
                var DTon = $(e.target).parent().parent().children().eq(1).text()
                var name = $("#Login_N").text()
                console.log(name)
                window.location.href = "/Application/Application?App_ban=" + DTon + "&Nameed=" + name + "&name=" + "设计委托2";
            })

            //点击重新编辑设计委托
            $(document).on("click", "#WT_bjwt", function (e) {
                var DTon = $(e.target).parent().parent().children().eq(1).text()
                console.log(DTon)
                var name = $("#Login_N").text()
                window.location.href = "/Application/Application?App_ban=" + DTon + "&Nameed=" + name+"&name=" + "设计委托";
            })
            $(document).on("click", "#BH_JL", function (e) {
                var DTon = $(e.target).parent().parent().children().eq(1).text()
                $.ajax({
                    url: '/Contracts/Inspect_Contracts',
                    type: 'GET',
                    data: { "D_Ton": DTon, "state": 6 },
                    success: function (zc) {
                        $("#WT_dh_mb").show()
                        $.each(zc, function (i, item) {
                            $("#WT_dhr").text(item.BH_ren)
                            $("#WT_dhly").text(item.BH_JL)
                        })
                    },
                    error: function () {
                        console.log("失败");
                    }
                })
            })

            //点击新增委托单
            //$(document).on("click", "#WT_xzwtd", function (e) {
            //    console.log(11)
            //    window.location.href = "/Contracts/Design_order"
            //})
            //点击查看所有委托单信息
            $(document).on("click", "#WT_cksywtd", function () {
                window.location.href ="/Contracts/Contracts_statement"
            })
            //-------
            function fenye(a) {
                var hjin = a * 1
                var shunddd = $("#komdr").text() * 1
                $(".pagination li").remove()
                var $ul = ""
                $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
                for (var i = 1; i <= shunddd; i++) {
                    if (shunddd < 4) {
                        if (i < 4) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                            break
                        }
                    }
                    if (shunddd >= 4) {
                        if (i < (hjin - 2) || i >= (hjin + 2)) {
                            continue
                        }
                        if (i > (hjin - 2) && i < (hjin + 2)) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                        }
                    }
                }
                $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
                $(".pagination").append($ul)
            }
            $(document).on("click", ".shiyong", function () {
                var shunddd = $("#komdr").text() * 1
                var sjind = $(this).text()
                sjind = sjind == "<<<" ? "1" : sjind == ">>>" ? shunddd : sjind * 1
                fenye(sjind)
                DAyin(sjind)
            })
        })
    </script>
}